<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>果然FruitC</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<link href="${ctx }/shop/css/amazeui.min.css" rel="stylesheet" type="text/css" />
		<link href="${ctx }/shop/css/style.css" rel="stylesheet" type="text/css" />
		<style>
		.yhq_price{
			margin-right:10px;
		    color: #cb2527;
		    font-size: 2rem;
		}
		</style>
	</head>
	<body>
		<header data-am-widget="header" class="am-header am-header-default sq-head ">
			<div class="am-header-left am-header-nav">
				<a href="${ctx }/shopcar" class="">
					<i class="am-icon-chevron-left"></i>
				</a>
			</div>
			<h1 class="am-header-title">
  	            <a href="" class="">确认订单</a>
            </h1>
	    </header>
	    <div style="height: 49px;"></div>
	    <h5 class="order-tit">收货人信息</h5>
	    <div class="order-name">
	    	<a href="${ctx }/address?type=order&addressid=${address.id}">
	    		<p class="order-tele">${address.name_}&nbsp;&nbsp;&nbsp;${address.mobile_}</p>
	    		<p class="order-add">${address.addr_ }</p>
	    	</a>
	    	<i class="am-icon-angle-right"></i>
	    </div>
	    
        <div style="background: #eee; height: 10px;"></div>
        <h5 class="order-tit">确认订单信息</h5>
        <ul class="shopcart-list" style="padding-bottom: 0; margin-top: 0;">
	    	<c:forEach items="${info }" var="record">
		    	<li id="${record.id }" shopcarid = "${record.shopcarid_ }">
	                <img src="${record.img_ }" class="shop-pic" />
	                <div class="order-mid">
	                	<div class="tit">${record.name_ }</div>
	                	<div class="order-price">￥<span class="price">${record.price_ }</span> <i>X<span class="num">${record.count_ }</span></i></div>
	                </div>
		    	</li>
	    	</c:forEach>
	    </ul>
	    <ul class="order-infor">
	    	<li class="order-infor-first">
	    		<span>商品总计：</span>
	    		<i id="total"></i>
	    	</li>
	    	<li class="order-infor-first">
	    		<span>运费：</span>
	    		<i>包邮</i>
	    	</li>
<!-- 	    	<li class="order-infor-first"> -->
<!-- 	    		<a href="integral.html">积分抵费></a> -->
<!-- 	    	</li> -->
	    	<li class="order-infor-first">
	    		<a href="javascript:showyhq();">选择优惠券></a>
	    	</li>
	    	<ul id="yhq" style="text-align:right;display:none;">
<!-- 	    		<div style="color: #909090;font-size:1rem;">无可用优惠券</div> -->
	    			<c:forEach items="${yhqs }" var="record">
		    			<li>
		    				<span class="ss" style="text-align:left;display:inline-block;">
		    					<input id="yhq${record.id }" onchange="yhqchange(this)" type="radio" name="yhq"/>
		    					<label for="yhq${record.id }" style="font-weight:normal;color: #909090;">
		    					<span>${record.desc_ }</span>
		    					</label>
		    				</span>
		    				
		    			</li>
	    			</c:forEach>
	    			<li>
		    				<span class="ss" style="text-align:left;display:inline-block;">
		    					<input id="yhq-1" onchange="yhqchange(this)" checked type="radio" name="yhq"/>
		    					<label for=yhq-1 style="font-weight:normal;color: #909090;">
		    					<c:choose>
		    						<c:when test="${yhqs.size()==0 }">
		    						<span>无可用优惠券</span>
		    						</c:when>
		    						<c:otherwise>
		    							<span>不使用优惠券</span>
		    						</c:otherwise>
		    					</c:choose>
		    					
		    					</label>
		    				</span>
		    				
		    			</li>
	    		</ul>
	    </ul>
	    <!--<div style="background: #eee; height: 10px;"></div>
	    
	    <input id="beginTime" class="select-time" placeholder="请选择配送时间 >" /></div>
		<div id="datePlugin"></div>-->
	    <div style="background: #eee; height: 10px;"></div>
	    <textarea id="desc" placeholder="备注说明" class="bz-infor"></textarea>
	    <div style="background: #eee; height: 10px;"></div>
	    <div class="shop-fix" style="position:initial;">
	    	<div class="order-text">
	    		应付总额：￥<span id="payPrice">188</span>
	    	</div>
	    	<form id="form" method="post" action="${ctx }/addOrder">
	    		<input id="address" name="address" value="${ address.id}" type="hidden"/>
	    		<input id="vals" name="vals" type="hidden"/>
	    		<input id="yhqval" name="yhqval" type="hidden"/>
	    		<input id="beizhu"  name="beizhu" type="hidden"/>
	    	</form>
	    	<a href="javascript:pay();" class="js-btn">提交订单</a>
	    </div>
<!--底部-->
<script src="${ctx }/shop/js/jquery-1.10.2.min.js"></script>
<script src="${ctx }/shop/js/util.js"></script>
 <script>
 $.ajax({
	 url : "${ctx}/checkorder",
	 async : false,
	 success : function(data){
		 if(data.status == true){
			 window.location.href = "${ctx}/shopcar";
		 }
	 }
 })
 var yhqobj = ${yhqjson};
 
 function yhqchange(obj){
	var id = obj.id;
	id = id.substring(3);
	var obj = yhqobj[id];
	if(!obj){
		$("#total").text(total);
		$("#payPrice").text(total);
		return;
	}
	var type = obj.type;
	var price = 0;
	if(1 == type){//减
		var money = obj.yhmoney;
		price = total-money;
	}else if(2 == type){//打折
		price = obj.discount * total;
	}
	price = price.toFixed(2);
	$("#total").text(price);
	$("#payPrice").text(price);
 }
 var sending = false;
 function pay(){
	 if(sending){
		return; 
	 }
	 var address = $("#address").val();
	 if(!address){
		 hit_box_one('收货地址不能为空','','','我知道啦','');
		 return;
	 }
	 var objs = [];
	 $(".shopcart-list li").each(function(){
			var self = this;
			var id = this.id;
			var num = $(".num",self).text();
			var shopcarid = $(this).attr("shopcarid");
			 var obj = {
					 count:num,
					 id : id,
					 shopcarid : shopcarid
			 }
			 objs.push(obj);
		});
	 $("#vals").val(JSON.stringify(objs));
	 var val = "";
	 $("#yhq input[name='yhq']").each(function(){
		 if(this.checked){
			 val = this.id.substring(3);
		 }
	 })
	 $("#yhqval").val(val);
	 $("#beizhu").val($("#desc").val());
	 sending = true;
	 $("#form")[0].submit();
 }
 
 window.onload = function(){
	 repairYHQ();
 }
 
 function repairYHQ(){//让优惠券统一
		$("#yhq").show();
		var spans = $("#yhq .ss")
		var maxWidth = 0;
		for(var i =0;i<spans.length;i++){
			var width = $(spans[i]).width();
			if(width > maxWidth){
				maxWidth = width;
			}
		}
		spans.width(maxWidth+10);
		$("#yhq").hide();
 }
	 var total = 0;
 $(document).ready(function(){
	$(".shopcart-list li").each(function(){
		var self = this;
		var price = $(".price",self).text();
		var num = $(".num",self).text();
		total +=num*price;
	}) 
	total = total.toFixed(2);
	$("#total").text(total);
	$("#payPrice").text(total);
 });
 var yhq = $("#yhq");
 	function showyhq(){
 		if(yhq.is(":hidden")){
 			yhq.fadeIn();
 		}else{
 			yhq.hide();
 		} 
 	}
 </script>
<%@include file="../common/jsticket.jsp"%><!--静态包含-->  
	</body>
</html>
